﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ESoft.Core.Data.Entity;
using ESoft.Core.Web.VO;

namespace ESoft.Core.Data.Service
{
    public interface IBaseService<T,TKey> where T : BaseModel<TKey>, new()
    {
        T Find(TKey id);
        T First(Expression<Func<T, bool>> predicate);
        T Add(T entity);
        bool Update(T entity);
        bool Delete(TKey id);
        bool Delete(T entity);
        bool Delete(IEnumerable<T> entities);
        bool Exist(Expression<Func<T, bool>> predicate);
        int Count(Expression<Func<T, bool>> predicate);
        int Sum(Expression<Func<T, bool>> predicate, Expression<Func<T, int>> selector);
        decimal Sum(Expression<Func<T, bool>> predicate, Expression<Func<T, decimal>> selector);
        IQueryable<T> LoadEntities() ;
        IQueryable<T> LoadEntities(Expression<Func<T, bool>> predicate);
        IQueryable<T> LoadPageEntities<TS>(PageInput page, Expression<Func<T, bool>> predicate,
            Expression<Func<T, TS>> keySelector, bool isAsc);
    }
}
